/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package dropbinserver.controller;

import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;

/**
 *
 * @author LegACy
 */
public class Listener implements Runnable {
	public Listener() {
		try {
			//Running
			m_Running = true;

			//Create server socket
			m_Server = new ServerSocket(10000);
		} catch (IOException ex) {}
	}

	public void run() {
		System.out.println("Listener is running");

		//Create another thread
		m_Responder = new Responder();
		new Thread(m_Responder).start();

		//While running
		while (m_Running) {
			try {
				//Sleep a bit
				Thread.sleep(20);
			} catch (InterruptedException ex) {}

			try {
				//Get new connection
				Socket NewConnection = m_Server.accept();
				if (NewConnection != null)	m_Responder.addConnection(NewConnection);
			} catch (IOException ex) {}
		}
	}

	protected ServerSocket	m_Server;
	protected Responder		m_Responder;
	protected boolean		m_Running;
}
